<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
</head>

<body>
    <script>
        // promise 是封装ajax用的
        function myajax(type, url, params) {
            var p = new Promise((res, rej) => {
                $.ajax({ // ajsx本身是异步代码
                    type,
                    url,
                    data: { ...params },
                    success(data) {
                        //在成功后调用的函数
                        res(data);
                    },
                    error(err) {
                        // 在失败后调用的函数
                        rej(err);
                    },
                })
            })
            return p;
        }
        var p1 = myajax('get', 'https://cnodejs.org/api/v1/topics', { page: 1 })
        /*   p1.then(function(res){
              console.log(res);
              
          }) */
        var p2 = p1.then(function (res) {
            console.log(res);
            return myajax('get', 'https://cnodejs.org/api/v1/topics', { page: 2 });
        })
        p2.then(function (res) {
            console.log(res);
        })
    </script>
</body>

</html>